package com.magicsoft.share.presenter.my;

import com.magicsoft.share.base.BasePresenter;
import com.magicsoft.share.bean.my.OrderList;
import com.magicsoft.share.constant.APIService;
import com.magicsoft.share.constant.SPKey;
import com.magicsoft.share.rx_retrofit_network.location.retrofit.RetrofitUtil;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.LoadingTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.NetWorkTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.SimpleObserver;
import com.magicsoft.share.utils.SPUtils;
import com.magicsoft.share.view.my.IOrderView;

import io.reactivex.annotations.NonNull;

/**
 * Created by lyf on 2017/11/23/023.
 */

public class OrderPresenter extends BasePresenter<IOrderView> {
    public void orderList(int status, int pageNum, int pageSize) {
        RetrofitUtil.getApi(APIService.class)
                .myOrderList(SPUtils.getInstance().getString(SPKey.TOKEN), SPUtils.getInstance().getLong(SPKey.ID), status, pageNum, pageSize)
                .compose(new NetWorkTransformer<OrderList>())
                .compose(new LoadingTransformer<OrderList>(mContext))
                .subscribe(new SimpleObserver<OrderList>(mCompositeDisposable) {
                    @Override
                    public void call(@NonNull OrderList orderList) {

                        getView().orderListSuccess(orderList);
                    }

                    @Override
                    public void showErrorMsg(Throwable e, String errorMsg) {
                        super.showErrorMsg(e, errorMsg);
                        getView().orderListFail();
                    }
                });
    }

    public void confirmOrder(long orderId) {
        RetrofitUtil.getApi(APIService.class)
                .confirmOrder(SPUtils.getInstance().getString(SPKey.TOKEN), orderId)
                .compose(new NetWorkTransformer())
                .compose(new LoadingTransformer(mContext))
                .subscribe(new SimpleObserver(mCompositeDisposable) {

                    @Override
                    public void call(@NonNull Object o) {
                        getView().confirmOrderSuccess();
                    }
                });
    }
}
